package com.yisoo.ubag.product.controller;

import java.util.*;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yisoo.ubag.product.entity.SceneEntity;
import com.yisoo.ubag.product.service.SceneService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-02-06 17:43:43
 */
@RestController
@RequestMapping("product/scene")
public class SceneController {
    @Autowired
    private SceneService sceneService;

//写入绑定品牌
    @PostMapping("/set/brand/{cid}/{sid}")
    public R setBrandRelated(@PathVariable("cid")Long cid, @PathVariable("sid") Long sid,@RequestBody JSONObject jsonParam){

        //根据用户id和场景id查出穿梭框数据
        return sceneService.setBrandRelated(cid,sid,(ArrayList<Integer>)jsonParam.get("value"));
    }

    //查新绑定品牌的关心
    @GetMapping("/get/brand/{cid}/{sid}")
    public R getBrandRelated(@PathVariable("cid")Long cid, @PathVariable("sid") Long sid){

        //根据用户id和场景id查出穿梭框数据
        return sceneService.getBrandRelated(cid,sid);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:scene:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sceneService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{sceneId}")
    //@RequiresPermissions("product:scene:info")
    public R info(@PathVariable("sceneId") Long sceneId){
		SceneEntity scene = sceneService.getById(sceneId);

        return R.ok().put("scene", scene);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:scene:save")
    public R save(@RequestBody SceneEntity scene){

        if (scene.getCreateTime() == null){
            scene.setCreateTime(new Date());
        }
		sceneService.save(scene);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:scene:update")
    public R update(@RequestBody SceneEntity scene){
		sceneService.updateById(scene);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:scene:delete")
    public R delete(@RequestBody Long[] sceneIds){
		sceneService.removeByIds(Arrays.asList(sceneIds));

        return R.ok();
    }

}
